$(document).ready(function() {
	$('#chatArea').ready(function() {
		$('#chatArea').css("height", $('#chat').height() * 0.7 + "px");
	});
	
	$('#chatSubmit').mousedown(function() {
		message = $('#chatInput').val();
		if (message !== "") {
			chatMessage(playerName, message);
		}
		$('#chatInput').val("");
	});
	
	$("#chatInput").keypress(function (event) {
		if (event.which == 13){
			message = $('#chatInput').val();
			if (message !== "") {
				chatMessage(playerName, message);
			}
			$('#chatInput').val("");
	    }
	});
});

$(window).resize(function() {
	$('#chatArea').ready(function() {
		$('#chatArea').css("height", $('#chat').height() * 0.7 + "px");
	});
});

function chatMessage(name, message) {
	$('#chatArea').val($('#chatArea').val() + (name + ": " + message + "\n"));
	$("#chatArea").animate({ scrollTop: $("#chatArea")[0].scrollHeight }, 1000);
}

function logMessage(message) {
	$('#chatArea').val($('#chatArea').val() + (" *** " + message + " ***\n"));
	$("#chatArea").animate({ scrollTop: $("#chatArea")[0].scrollHeight }, 1000);
}